package com.itqf.quartz;

import com.itqf.job.TimeJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * projectName: logandquartzgp8
 *
 * @author: 赵伟风
 * time: 2021/8/10 15:59
 * description:
 */
public class SimpleJob {

    public static void main(String[] args) throws SchedulerException {

        //1.创建jobDetail
        JobDetail jobDetail = JobBuilder.newJob(TimeJob.class).build();

        //2.创建SimpleTrigger
        /**
         * 16:00 - 16:05  每10秒触发一次job
         */

        Date start = DateBuilder.dateOf(16, 11, 0);
        Date end = DateBuilder.dateOf(16, 15, 0);

        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().startAt(start).endAt(end)
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(10).repeatForever()).build();


        //3.创建调度任务Scheduler
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();

        //4.启动调度任务
        Scheduler scheduler = stdSchedulerFactory.getScheduler();

        //5.添加jobDetail和simpleTrigger
        scheduler.scheduleJob(jobDetail, simpleTrigger);
        scheduler.start();


    }
}
